package com.neuedu.hisweb.controller.neureg;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.hisweb.entity.*;
import com.neuedu.hisweb.entity.vo.RegParam;
import com.neuedu.hisweb.entity.vo.RegisterVo;
import com.neuedu.hisweb.service.IRegisterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/register")
public class RegisterController {
    @Autowired
    private IRegisterService iRegisterService;

    @GetMapping("/page")
    public JsonResult<Page> getRegInfoByPage(@RequestParam(value = "pn", defaultValue = "1") Integer pn,
                                             @RequestParam(value = "count", defaultValue = "10") Integer count,
                                             @RequestParam(value = "keyword",required = false)String keyword,

                                             @RequestParam(value ="deptId",required = false)Integer deptId,
                                             @RequestParam(value = "docId", required = false) Integer docId,
                                             @RequestParam(value = "state", required = false) Integer state,
                                             @RequestParam(value = "regDate", required = false) String regDate
    ){
        Page<RegisterVo> page=Page.of(pn,count);
//        Page<RegisterVo> selectPage(Page<RegisterVo> page,Integer deptId,Integer docId,Integer state,String keyword,String regDate);
        iRegisterService.selectPage(page,deptId,docId,state,keyword,regDate);
        return new JsonResult<Page>(page);
    }

    @PostMapping("/add")
    public JsonResult<Register>addUser(@RequestBody RegParam param){
        boolean rs=iRegisterService.saveRegister(param);
        if(rs)return new JsonResult<>(true);
        else return new JsonResult<>("添加失败");
    }

    @PostMapping("/del")
    public JsonResult<Register> delMedicalCard(@RequestParam(value = "id", required = true) Integer id) {
        boolean rs = iRegisterService.removeById(id);
        if (rs) {
            JsonResult<Register> jsonResult = new JsonResult<>();
            jsonResult.setResult(true);
            return jsonResult;
        } else return new JsonResult<Register>("删除失败");
    }





}
